package com.rt.easyjava.base.biz1.bean.base;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.rt.easyjava.base.biz1.bean.TmptTableBiz;
import com.rt.easyjava.base.biz1.bean.TmptTbColumnBiz;
import com.rt.easyjava.common.base.UserDetailsDto;
import lombok.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;


/**
 *
 * @author wuxiaoyong
 * @since 2020-11-13
 */

@Data
@ToString
@EqualsAndHashCode(callSuper = false)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TmptTable extends Model<TmptTableBiz>{

    private String datasource;
    private Integer hasdelbtn;
    private Integer hascompanyid;
    private String styleAdddialog;
    private Integer isdialogAdddialog;
    private Long createmanId;
    private Long modifymanId;
    private Long companyId;
    private String treeJson;
    private String idType;
    private String btnMulti;
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    private String keyrandom;
    private Integer mode;
    private String primarykey;
    private String tablename;
    private String tablenameshow;
    private String one2many;
    private Integer hasaddbtn;
    private Integer hasdownloadreportbtn;
    private Integer haseditbtn;
    private Integer hashistorybtn;
    private String beanmethod;
    private String beanobject;
    private String beanhistorymethod;
    private String tablealiasname;
    private String sqlcount;
    private String tablenamehistorysql;
    private String tablenamesql;
    private String sqlcounthistory;
    private String sqlpage;
    private String sqlpagehistory;
    private String sqlreport;
    private String version;
    private String sqlsum;
    private Date createdate;
    private String createman;
    private Integer deleteflag;
    private Date modifydate;
    private String modifyman;
    private String foreignkey;
    private String sqlprocedure;
    private Integer height4adddialog;
    private Integer width4adddialog;
    private String chartjson;
    private Integer chartheight;
    private Integer chartwidth;
    private String interceptaddmethod;
    private String intercepteditmethod;
    private String interceptobject;
    private Integer hascheckbox;


    // One to Many
    @TableField(exist = false)
    private List<TmptTbColumnBiz> tmptTbColumnList;



    // 重写这个方法，return当前类的主键
    @Override
    protected Serializable pkVal() {
        return id;
    }

    // set deleteflag default 0, 查询参数时，默认只查有效数据
    public void setDeleteflagDefaultZero(){
        if(this.deleteflag==null){
            this.setDeleteflag(0);
        }
    }

    // 数据访问边界 0：全部数据， 10：机构内部数据
    public void rebuildDataLimitQueryBean(UserDetailsDto userDetailsDto){
        if (userDetailsDto==null) return;
        int dataLimitType = userDetailsDto.getDataLimitType();
        if (dataLimitType >= 10) {
            this.setCompanyId(Long.parseLong(userDetailsDto.getCompanyId()));
        }
        if (dataLimitType >= 20) {
            this.setCreatemanId(Long.parseLong(userDetailsDto.getUserId()));
        }
    }

}
